home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1996, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* point_parameters.c
- * This program demonstrates GL_SGIS_point_parameters. It
- * allows you to change various point attributes dynamically.
- *
- * <a/A> key - increase/decrease the 'a' coefficient
- * <b/B> key - increase/decrease the 'b' coefficient
- * <c/C> key - increase/decrease the 'c' coefficient
- * <f/F> key - increase/decrease the fade threshold size
- * <m/M> key - increase/decrease the minimum point size
- * <x/X> key - increase/decrease the maximum point size
- * Escape key - exit the program
- */
- #include <GL/gl.h>
- #include <GL/glu.h>
- #include <GL/glut.h>
-
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
-
- /* Function Prototypes */
-
- GLvoid initgfx( GLvoid );
- GLvoid drawScene( GLvoid );
- GLvoid reshape( GLsizei, GLsizei );
- GLvoid keyboard( GLubyte, GLint, GLint );
-
- GLvoid incFadeSize( GLvoid );
- GLvoid decFadeSize( GLvoid );
- GLvoid incCoefficient( GLint );
- GLvoid decCoefficient( GLint );
- GLvoid incMinSize( GLvoid );
- GLvoid decMinSize( GLvoid );
- GLvoid incMaxSize( GLvoid );
- GLvoid decMaxSize( GLvoid );
-
- void printHelp( char * );
-
- /* Global Definitions */
-
- #define KEY_ESC 27 /* ascii value for the escape key */
-
- /* Global Variables */
-
- static GLfloat coefficients[3] = { 1.0, 0.0, 0.0 };
-
- static GLfloat fadeSize = 1.0;
- static GLfloat minSize = 0.0;
- static GLfloat maxSize = 0.0;
-
- static GLfloat angle = 80.0;
-
- static GLboolean pointParameterSupported = GL_TRUE;
-
- void
- main( int argc, char *argv[] )
- {
- GLsizei width, height;
-
- glutInit( &argc, argv );
-
- width = glutGet( GLUT_SCREEN_WIDTH );
- height = glutGet( GLUT_SCREEN_HEIGHT );
- glutInitWindowPosition( width/4, height/4 );
- glutInitWindowSize( width/2, height/2 );
- glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE );
- glutCreateWindow( argv[0] );
-
- initgfx();
-
- glutKeyboardFunc( keyboard );
- glutReshapeFunc( reshape );
- glutDisplayFunc( drawScene );
-
- printHelp( argv[0] );
-
- glutMainLoop();
- }
-
- GLvoid
- printHelp( char *progname )
- {
- fprintf(stdout,"\n%s - demonstrates point parameters\n\n"
- "<a/A> key - increase/decrease the 'a' coefficient\n"
- "<b/B> key - increase/decrease the 'b' coefficient\n"
- "<c/C> key - increase/decrease the 'c' coefficient\n"
- "<f/F> key - increase/decrease the fade threshold size\n"
- "<m/M> key - increase/decrease the minimum point size\n"
- "<x/X> key - increase/decrease the maximum point size\n"
- "Escape key - exit the program\n\n",
- progname
- );
- }
-
- GLvoid
- initgfx( GLvoid )
- {
- glClearColor( 0.0, 0.0, 0.0, 0.0 );
- glClear( GL_COLOR_BUFFER_BIT );
-
- if (!glutExtensionSupported("GL_SGIS_point_parameters")) {
- pointParameterSupported = GL_FALSE;
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- }
-
- GLvoid
- decFadeSize( GLvoid )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- if ( fadeSize > 0 ) fadeSize -= 0.1;
- printf( "fadeSize = %4.2f\n", fadeSize );
- glPointParameterfSGIS( GL_POINT_FADE_THRESHOLD_SIZE_SGIS, fadeSize );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
-
- }
-
- GLvoid
- incFadeSize( GLvoid )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- fadeSize += 0.1;
- printf( "fadeSize = %4.2f\n", fadeSize );
- glPointParameterfSGIS( GL_POINT_FADE_THRESHOLD_SIZE_SGIS, fadeSize );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
- }
-
- GLvoid
- decCoefficient( GLint i )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- if ( coefficients[i] > 0 ) coefficients[i] -= 0.1;
- printf( "coefficients[%d] = %4.2f\n", i, coefficients[i] );
- glPointParameterfvSGIS( GL_DISTANCE_ATTENUATION_SGIS, coefficients );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
- }
-
- GLvoid
- incCoefficient( GLint i )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- coefficients[i] += 0.1;
- printf( "coefficients[%d] = %4.2f\n", i, coefficients[i] );
- glPointParameterfvSGIS( GL_DISTANCE_ATTENUATION_SGIS, coefficients );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
- }
-
- GLvoid
- decMinSize( GLvoid )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- if ( minSize > 0 ) minSize -= 0.1;
- printf( "minSize = %4.2f\n", minSize );
- glPointParameterfSGIS( GL_POINT_SIZE_MIN_SGIS, minSize );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
- }
-
- GLvoid
- incMinSize( GLvoid )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- minSize += 0.1;
- printf( "minSize = %4.2f\n", minSize );
- glPointParameterfSGIS( GL_POINT_SIZE_MIN_SGIS, minSize );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
- }
-
- GLvoid
- decMaxSize( GLvoid )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- if ( maxSize > 0 ) maxSize -= 0.1;
- printf( "maxSize = %4.2f\n", maxSize );
- glPointParameterfSGIS( GL_POINT_SIZE_MAX_SGIS, maxSize );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
- }
-
- GLvoid
- incMaxSize( GLvoid )
- {
- #ifdef GL_SGIS_point_parameters
- if (pointParameterSupported) {
- maxSize += 0.1;
- printf( "maxSize = %4.2f\n", maxSize );
- glPointParameterfSGIS( GL_POINT_SIZE_MAX_SGIS, maxSize );
- glutPostRedisplay();
- } else {
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- }
- #else
- fprintf( stderr,
- "GL_SGIS_point_parameters not supported on this machine\n");
- #endif
- }
-
- GLvoid
- keyboard( GLubyte key, GLint x, GLint y )
- {
- switch (key) {
- case 'a': /* decrement coefficient a */
- decCoefficient(0);
- break;
- case 'A': /* increment coefficient a */
- incCoefficient(0);
- break;
- case 'b': /* decrement coefficient b */
- decCoefficient(1);
- break;
- case 'B':
- incCoefficient(1);
- break;
- case 'c': /* decrement coefficient c */
- decCoefficient(2);
- break;
- case 'C':
- incCoefficient(2);
- break;
- case 'f': /* decrement fade size */
- decFadeSize();
- break;
- case 'F':
- incFadeSize();
- break;
- case 'm': /* decrement min size */
- decMinSize();
- break;
- case 'M':
- incMinSize();
- break;
- case 'x': /* decrement max size */
- decMaxSize();
- break;
- case 'X':
- incMaxSize();
- break;
- case KEY_ESC: /* Exit when the Escape key is pressed */
- exit(0);
- }
- }
-
- GLvoid
- reshape( GLsizei width, GLsizei height )
- {
- GLdouble aspect;
-
- glViewport( 0, 0, width, height );
-
- aspect = (GLdouble) width / (GLdouble) height;
-
- glMatrixMode( GL_PROJECTION );
- glLoadIdentity();
- glOrtho (0.0,1.0,0.0,1.0,1.0,-1.0);
- glMatrixMode( GL_MODELVIEW );
- glLoadIdentity();
- }
-
- static void Draw_Points0 (void)
- {
- glPointSize (3);
- glBegin (GL_POINTS);
- glVertex4f (0.12,0.11,0.0,1.0);
- glVertex4f (0.14,0.12,0.0,1.0);
- glVertex4f (0.16,0.13,0.0,1.0);
- glVertex4f (0.18,0.14,0.0,1.0);
- glVertex4f (0.20,0.15,0.0,1.0);
- glVertex4f (0.22,0.16,0.0,1.0);
- glVertex4f (0.24,0.17,0.0,1.0);
- glEnd();
- glTranslatef (0.0,0.1,0.0);
- }
-
-
- static void Draw_Points1 (void)
- {
- glPointSize(2);
-
- glBegin(GL_POINTS);
- glVertex4f (0.10,0.10,0.0,1.0);
- glEnd ();
-
- glPointSize (3);
-
- glBegin (GL_POINTS);
- glVertex4f (0.12,0.11,0.0,1.0);
- glVertex4f (0.14,0.12,0.0,1.0);
- glEnd();
-
- glPointSize (4);
-
- glBegin (GL_POINTS);
- glVertex4f (0.16,0.13,0.0,1.0);
- glVertex4f (0.18,0.14,0.0,1.0);
- glVertex4f (0.20,0.15,0.0,1.0);
- glEnd();
-
- glTranslatef (0.0,0.1,0.0);
- }
-
-
- GLvoid
- drawScene( GLvoid )
- {
- glClear( GL_COLOR_BUFFER_BIT );
-
- glPushMatrix();
-
- glColor4f (1.0,1.0,1.0,1.0);
-
- /* draw some aliased points */
- Draw_Points0 ();
-
- /* move over a bit and draw the same points,
- * with antialiasing */
-
- glBlendFunc (GL_SRC_ALPHA,GL_ONE);
- glEnable (GL_BLEND);
- glEnable (GL_POINT_SMOOTH);
- Draw_Points0 ();
- glBlendFunc (GL_ONE,GL_ZERO);
- glDisable (GL_BLEND);
- glDisable (GL_POINT_SMOOTH);
-
- /* draw some more aliased points */
- Draw_Points1 ();
-
- /* move over a bit and draw the same points,
- * with antialiasing */
-
- glBlendFunc (GL_SRC_ALPHA,GL_ONE);
- glEnable (GL_BLEND);
- glEnable (GL_POINT_SMOOTH);
- Draw_Points1 ();
- glBlendFunc (GL_ONE,GL_ZERO);
- glDisable (GL_BLEND);
- glDisable (GL_POINT_SMOOTH);
-
- /* draw a few very large points */
-
- glPointSize(8);
- glBegin(GL_POINTS);
- glVertex4f (0.10,0.10,0.0,1.0);
- glEnd ();
-
- glTranslatef (0.0,0.1,0.0);
-
- glBegin(GL_POINTS);
- glVertex4f (0.10,0.10,0.0,1.0);
- glEnd ();
-
- glPopMatrix();
-
- glutSwapBuffers();
-
- checkError("drawScene");
- }
-